
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;
import java.sql.*;

final class EditVendor extends javax.swing.JInternalFrame {
    PreparedStatement statement;
    ResultSet result;
    Systems systems=new Systems();
    Thread editVendorThread=new Thread();
    Thread editVendorTitleThread=new Thread();

    String dbName="";
    String dbAddress="";
    String dbPhoneNo="";
    String dbCountryCode="";
    String dbCountry="";
    String dbZip="";
    String dbState="";
    String dbRegNo="";
    String dbCity="";

    /** Creates new form Customer */
     EditVendor() {
        initComponents();
        /* Execute submit thread */
        editVendorThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                resetVendorID();
                resetCountry();
            }
        });
        editVendorTitleThread=new Thread(new Runnable() {
            public void run() {
                while(editVendorThread.isAlive())setProcessingTitle(editVendorTitleThread);
                enableControls();
                System.out.println("editVendorThread stopped runing.");
            }
        });
        editVendorThread.start();
        editVendorTitleThread.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jAddressLabel = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jCountryComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jAddressTextArea = new javax.swing.JTextArea();
        jUpdateButton = new javax.swing.JButton();
        jNameTextField = new javax.swing.JTextField();
        jPhoneTextField = new javax.swing.JTextField();
        jZipTextField = new javax.swing.JTextField();
        jRegNoTextField = new javax.swing.JTextField();
        jCityTextField = new javax.swing.JTextField();
        jStateTextField = new javax.swing.JTextField();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        jCheckBox7 = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        vendorIDComboBox = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();

        setClosable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(EditVendor.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setRequestFocusEnabled(false);
        try {
            setSelected(true);
        } catch (java.beans.PropertyVetoException e1) {
            e1.printStackTrace();
        }
        setVisible(true);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jAddressLabel.setText(resourceMap.getString("jAddressLabel.text")); // NOI18N
        jAddressLabel.setName("jAddressLabel"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jCountryComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jCountryComboBox.setEnabled(false);
        jCountryComboBox.setName("jCountryComboBox"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jAddressTextArea.setColumns(20);
        jAddressTextArea.setEditable(false);
        jAddressTextArea.setLineWrap(true);
        jAddressTextArea.setRows(5);
        jAddressTextArea.setText(resourceMap.getString("jAddressTextArea.text")); // NOI18N
        jAddressTextArea.setEnabled(false);
        jAddressTextArea.setName("jAddressTextArea"); // NOI18N
        jAddressTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jAddressTextAreaKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(jAddressTextArea);

        jUpdateButton.setFont(resourceMap.getFont("jUpdateButton.font")); // NOI18N
        jUpdateButton.setIcon(resourceMap.getIcon("jUpdateButton.icon")); // NOI18N
        jUpdateButton.setText(resourceMap.getString("jUpdateButton.text")); // NOI18N
        jUpdateButton.setName("jUpdateButton"); // NOI18N
        jUpdateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUpdateButtonActionPerformed(evt);
            }
        });

        jNameTextField.setEditable(false);
        jNameTextField.setText(resourceMap.getString("jNameTextField.text")); // NOI18N
        jNameTextField.setName("jNameTextField"); // NOI18N
        jNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jNameTextFieldActionPerformed(evt);
            }
        });

        jPhoneTextField.setEditable(false);
        jPhoneTextField.setText(resourceMap.getString("jPhoneTextField.text")); // NOI18N
        jPhoneTextField.setName("jPhoneTextField"); // NOI18N
        jPhoneTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jPhoneTextFieldKeyTyped(evt);
            }
        });

        jZipTextField.setEditable(false);
        jZipTextField.setText(resourceMap.getString("jZipTextField.text")); // NOI18N
        jZipTextField.setName("jZipTextField"); // NOI18N
        jZipTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jZipTextFieldKeyTyped(evt);
            }
        });

        jRegNoTextField.setEditable(false);
        jRegNoTextField.setText(resourceMap.getString("jRegNoTextField.text")); // NOI18N
        jRegNoTextField.setName("jRegNoTextField"); // NOI18N
        jRegNoTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jRegNoTextFieldKeyTyped(evt);
            }
        });

        jCityTextField.setEditable(false);
        jCityTextField.setText(resourceMap.getString("jCityTextField.text")); // NOI18N
        jCityTextField.setName("jCityTextField"); // NOI18N
        jCityTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jCityTextFieldKeyTyped(evt);
            }
        });

        jStateTextField.setEditable(false);
        jStateTextField.setText(resourceMap.getString("jStateTextField.text")); // NOI18N
        jStateTextField.setName("jStateTextField"); // NOI18N
        jStateTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jStateTextFieldKeyTyped(evt);
            }
        });

        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jCheckBox2.setName("jCheckBox2"); // NOI18N
        jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox2ActionPerformed(evt);
            }
        });

        jCheckBox3.setName("jCheckBox3"); // NOI18N
        jCheckBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox3ActionPerformed(evt);
            }
        });

        jCheckBox4.setName("jCheckBox4"); // NOI18N
        jCheckBox4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox4ActionPerformed(evt);
            }
        });

        jCheckBox5.setName("jCheckBox5"); // NOI18N
        jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox5ActionPerformed(evt);
            }
        });

        jCheckBox6.setName("jCheckBox6"); // NOI18N
        jCheckBox6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox6ActionPerformed(evt);
            }
        });

        jCheckBox7.setName("jCheckBox7"); // NOI18N
        jCheckBox7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox7ActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        vendorIDComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        vendorIDComboBox.setName("vendorIDComboBox"); // NOI18N
        vendorIDComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vendorIDComboBoxActionPerformed(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton2.font")); // NOI18N
        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane1)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPhoneTextField)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox2)
                            .addComponent(jCheckBox3)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(vendorIDComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jAddressLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jRegNoTextField)
                                    .addComponent(jCityTextField)
                                    .addComponent(jStateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(43, 43, 43)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jZipTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jCountryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jUpdateButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton2)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox7)
                            .addComponent(jCheckBox6)
                            .addComponent(jCheckBox5)
                            .addComponent(jCheckBox4)
                            .addComponent(jCheckBox1))))
                .addGap(29, 29, 29))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBox1)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(jRegNoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel7)
                                .addComponent(jCityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jCheckBox4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBox5)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jStateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel8)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel6)
                                    .addComponent(jCountryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(11, 11, 11)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jCheckBox7)
                                        .addComponent(jZipTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(jCheckBox6)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(vendorIDComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jAddressLabel))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(70, 70, 70)
                                .addComponent(jCheckBox2)
                                .addGap(36, 36, 36)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBox3)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel4)
                                        .addComponent(jPhoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jUpdateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(74, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNameTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jNameTextFieldActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox1.isSelected())            
        {
            jRegNoTextField.setEnabled(true);
            jRegNoTextField.setEditable(true);
        }
        else
        {
            jRegNoTextField.setEnabled(false);
            jRegNoTextField.setEditable(false);
            jRegNoTextField.setText(dbRegNo);
        
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox2ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox2.isSelected())
        {
            jAddressTextArea.setEnabled(true);
            jAddressTextArea.setEditable(true);
        }
        else
        {
            jAddressTextArea.setEnabled(false);
            jAddressTextArea.setEditable(false);
            jAddressTextArea.setText(dbAddress);

        }
    }//GEN-LAST:event_jCheckBox2ActionPerformed

    private void jCheckBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox3ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox3.isSelected())
        {
            jPhoneTextField.setEnabled(true);
            jPhoneTextField.setEditable(true);
        }
        else
        {
            jPhoneTextField.setEnabled(false);
            jPhoneTextField.setEditable(false);
            jPhoneTextField.setText(dbPhoneNo);

        }
    }//GEN-LAST:event_jCheckBox3ActionPerformed

    private void jCheckBox4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox4ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox4.isSelected())
        {
            jCityTextField.setEnabled(true);
            jCityTextField.setEditable(true);
        }
        else
        {
            jCityTextField.setEnabled(false);
            jCityTextField.setEditable(false);
            jCityTextField.setText(dbCity);
        }
    }//GEN-LAST:event_jCheckBox4ActionPerformed

    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox5.isSelected())            
        {
            jStateTextField.setEnabled(true);
            jStateTextField.setEditable(true);
        }
        else
        {
            jStateTextField.setEnabled(false);
            jStateTextField.setEditable(false);
            jStateTextField.setText(dbState);
        
        }
    }//GEN-LAST:event_jCheckBox5ActionPerformed

    private void jCheckBox6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox6ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox6.isSelected())            
        {
            jCountryComboBox.setEnabled(true);
        }
        else
        {
            jCountryComboBox.setEnabled(false);
            if(dbCountry.isEmpty())
            {
            resetCountry();}
            else
            {
            jCountryComboBox.setSelectedItem(dbCountry);
            }
        
        }
    }//GEN-LAST:event_jCheckBox6ActionPerformed

    private void jCheckBox7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox7ActionPerformed
        // TODO add your handling code here:
        if(jCheckBox7.isSelected())            
        {
            jZipTextField.setEnabled(true);
            jZipTextField.setEditable(true);
        }
        else
        {
            jZipTextField.setEnabled(false);
            jZipTextField.setEditable(false);
            jZipTextField.setText(dbZip);
        
        }
    }//GEN-LAST:event_jCheckBox7ActionPerformed

    private void jUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUpdateButtonActionPerformed
        // TODO add your handling code here:

        if(vendorIDComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select a Vendor ID ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        if(isCheckBoxesFalse()==false)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame()," No Data Has Been Edited ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }

        String value=jPhoneTextField.getText().trim();
        int x=value.length();
        int y=0;
        char[] ch=value.toCharArray();

        if(jNameTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Vendor's Name ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jAddressTextArea.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Vendor's Address ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jPhoneTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Vendor's Phone Number ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }


        while(y<x)
        {
        try
        {
            if(Character.isDigit(ch[y]))
            {}
            else{
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Vendor's Phone Number Must Be in Digits","ERROR !",JOptionPane.ERROR_MESSAGE);
            return; }
        }
        catch(Exception e)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Phone Number Can Not Contain Alphabets","ERROR !",JOptionPane.ERROR_MESSAGE);
        jPhoneTextField.setText("");
        System.out.println(e+" Non int available in "+value+" non int is "+ch[y]);
        return;
        }
        y++;
        }


        if(jCityTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Vendor's City ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jStateTextField.getText().trim().isEmpty())
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Enter Vendor's State ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(jCountryComboBox.getSelectedItem().equals("-- Select --"))
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select Vendor's Country ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }

        else
        {
        /* Execute submit thread */
        editVendorThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                submitData();
                resetVendorID();
                resetFields();
                resetCheckBoxes();
                disableFields();
            }
        });
        editVendorTitleThread=new Thread(new Runnable() {
            public void run() {
                while(editVendorThread.isAlive())setProcessingTitle(editVendorTitleThread);
                enableControls();
                System.out.println("editVendorThread stopped runing.");
            }
        });
        editVendorThread.start();
        editVendorTitleThread.start();
        }
    }//GEN-LAST:event_jUpdateButtonActionPerformed
                  
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. Edit Vendor - Processing Request");
            thread.sleep(500);
            this.setTitle("::. Edit Vendor - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. Edit Vendor - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. Edit Vendor - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if(editVendorThread.isAlive())
        {
            try{
                editVendorThread.stop();
                editVendorTitleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. Edit Vendor");
            enableControls();
        }
        else
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void vendorIDComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vendorIDComboBoxActionPerformed
        
        /* Execute submit thread */
        editVendorThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                vendorIDSelected();
            }
        });
        editVendorTitleThread=new Thread(new Runnable() {
            public void run() {
                while(editVendorThread.isAlive())setProcessingTitle(editVendorTitleThread);
                enableControls();
                System.out.println("editVendorThread stopped runing.");
            }
        });
        editVendorThread.start();
        editVendorTitleThread.start();
    }//GEN-LAST:event_vendorIDComboBoxActionPerformed
    private void vendorIDSelected()
    {
        String vendorID=vendorIDComboBox.getSelectedItem().toString();
        if(vendorID.equals("-- Select --"))
        {
            resetVendorID();
            resetFields();            
        }
        else
        {
            try
            {
                //Connect.createMSSQLConnection();
                Connect.changeDB(OpenMSApp.Database_A);
                statement=Connect.createStatement("Select * from Vendor where cVendorID= '"+vendorID+"'");
                result=Connect.executeRStatement(statement);
                result.next();
                dbName=result.getString(2).trim();
                dbAddress=result.getString(3).trim();
                dbCity=result.getString(4).trim();
                dbState=result.getString(5).trim();
                dbCountryCode=result.getString(6).trim();
                dbZip=result.getString(7).trim();
                dbPhoneNo=result.getString(8).trim();
                dbRegNo=result.getString(9).trim();

                Connect.closeConnection();
            }
            catch(Exception e)
            {
                System.out.println("Sql errror! at EditVendor.vendorIDComboBoxActionPerformed "+e);
            }

            dbCountry=systems.getValue(OpenMSApp.Database_A,"Select * from country where cCountryCode= '"+dbCountryCode+"'","vCountryName");

            jAddressTextArea.setText(dbAddress);
            jNameTextField.setText(dbName);
            jCityTextField.setText(dbCity);
            jStateTextField.setText(dbState);
            jRegNoTextField.setText(dbRegNo);
            jZipTextField.setText(dbZip);
            jPhoneTextField.setText(dbPhoneNo);
            jCountryComboBox.setSelectedItem(dbCountry);
        }
            disableFields();
            resetCheckBoxes();
    }
    private void jAddressTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jAddressTextAreaKeyTyped
        // TODO add your handling code here:
        String value=jAddressTextArea.getText();
        if(value.length()>79)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (80) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 79);
        jAddressTextArea.setText(newValue);
        }
    }//GEN-LAST:event_jAddressTextAreaKeyTyped

    private void jPhoneTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPhoneTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jPhoneTextField.getText();
        if(value.length()>14)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (15) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 14);
        jPhoneTextField.setText(newValue);
        }
    }//GEN-LAST:event_jPhoneTextFieldKeyTyped

    private void jRegNoTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jRegNoTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jRegNoTextField.getText();
        if(value.length()>9)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (10) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 9);
        jRegNoTextField.setText(newValue);
        }
    }//GEN-LAST:event_jRegNoTextFieldKeyTyped

    private void jCityTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jCityTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jCityTextField.getText();
        if(value.length()>14)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (15) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 14);
        jCityTextField.setText(newValue);
        }
    }//GEN-LAST:event_jCityTextFieldKeyTyped

    private void jStateTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jStateTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jStateTextField.getText();
        if(value.length()>14)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (15) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 14);
        jStateTextField.setText(newValue);
        }
    }//GEN-LAST:event_jStateTextFieldKeyTyped

    private void jZipTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jZipTextFieldKeyTyped
        // TODO add your handling code here:
        String value=jZipTextField.getText();
        if(value.length()>7)
        {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Maximum Number of Character (8) Exceeded ","ERROR !",JOptionPane.ERROR_MESSAGE);
        String newValue=String.copyValueOf(value.toCharArray(),0, 7);
        jZipTextField.setText(newValue);
        }
    }//GEN-LAST:event_jZipTextFieldKeyTyped

     void resetCountry()
    {
        String[] country=systems.getTableDataArray(OpenMSApp.Database_A,"Country",2);
        country[0]="-- Select --";

        jCountryComboBox.setModel(new DefaultComboBoxModel(country));
        jCountryComboBox.setSelectedItem("NIGERIA");

    }
     void resetVendorID()
    {
        systems=new Systems();
        String[] vendorID=systems.getTableDataArray(OpenMSApp.Database_A,"Vendor",1);
        vendorID[0]="-- Select --";

        vendorIDComboBox.setModel(new DefaultComboBoxModel(vendorID));

    }
     void disableFields()
    {
            jAddressTextArea.setEnabled(false);
            jAddressTextArea.setEditable(false);

            jNameTextField.setEnabled(false);
            jNameTextField.setEditable(false);

            jCityTextField.setEnabled(false);
            jCityTextField.setEditable(false);

            jStateTextField.setEnabled(false);
            jStateTextField.setEditable(false);

            jRegNoTextField.setEnabled(false);
            jRegNoTextField.setEditable(false);

            jZipTextField.setEnabled(false);
            jZipTextField.setEditable(false);

            jPhoneTextField.setEnabled(false);
            jPhoneTextField.setEditable(false);

            jCountryComboBox.setEnabled(false);
            jCountryComboBox.setEditable(false);     
    }
    private void disableControls()
    {
            jAddressTextArea.setEnabled(false);
            jAddressTextArea.setEditable(false);

            jNameTextField.setEnabled(false);
            jNameTextField.setEditable(false);

            jCityTextField.setEnabled(false);
            jCityTextField.setEditable(false);

            jStateTextField.setEnabled(false);
            jStateTextField.setEditable(false);

            jRegNoTextField.setEnabled(false);
            jRegNoTextField.setEditable(false);

            jZipTextField.setEnabled(false);
            jZipTextField.setEditable(false);

            jPhoneTextField.setEnabled(false);
            jPhoneTextField.setEditable(false);

            jCountryComboBox.setEnabled(false);
            jCountryComboBox.setEditable(false);  
            
            jUpdateButton.setEnabled(false);
            vendorIDComboBox.setEnabled(false);
            
        jCheckBox1.setSelected(false);
        jCheckBox2.setSelected(false);
        jCheckBox3.setSelected(false);
        jCheckBox4.setSelected(false);
        jCheckBox5.setSelected(false);
        jCheckBox6.setSelected(false);
        jCheckBox7.setSelected(false);

    }
    private void enableControls()
    {
        jCheckBox1.setSelected(true);
        jCheckBox2.setSelected(true);
        jCheckBox3.setSelected(true);
        jCheckBox4.setSelected(true);
        jCheckBox5.setSelected(true);
        jCheckBox6.setSelected(true);
        jCheckBox7.setSelected(true);
        
        if(jCheckBox2.isSelected())
        {
            jAddressTextArea.setEnabled(true);
            jAddressTextArea.setEditable(true);
        }

        if(jCheckBox4.isSelected())
        {
            jCityTextField.setEnabled(true);
            jCityTextField.setEditable(true);
        }

        if(jCheckBox5.isSelected())            
        {
            jStateTextField.setEnabled(true);
            jStateTextField.setEditable(true);
        }

        if(jCheckBox1.isSelected())            
        {
            jRegNoTextField.setEnabled(true);
            jRegNoTextField.setEditable(true);
        }

        if(jCheckBox7.isSelected())            
        {
            jZipTextField.setEnabled(true);
            jZipTextField.setEditable(true);
        }

        if(jCheckBox7.isSelected())            
        {
            jZipTextField.setEnabled(true);
            jZipTextField.setEditable(true);
        }

        if(jCheckBox6.isSelected())            
        {
            jCountryComboBox.setEnabled(true);
        }
            
            jUpdateButton.setEnabled(true);
            vendorIDComboBox.setEnabled(true);
            

    }
     void resetFields()
    {
        jAddressTextArea.setText("");
        jNameTextField.setText("");
        jCityTextField.setText("");
        jStateTextField.setText("");
        jRegNoTextField.setText("");
        jZipTextField.setText("");
        jPhoneTextField.setText("");
        jCountryComboBox.setSelectedItem("-- Select --");     

    }
     boolean isCheckBoxesFalse()
    {
        boolean state = true;
        if((!jCheckBox1.isSelected())&&(!jCheckBox2.isSelected())&&(!jCheckBox3.isSelected())&&(!jCheckBox4.isSelected())&&(!jCheckBox5.isSelected())
                &&(!jCheckBox6.isSelected())&&(!jCheckBox7.isSelected()))
        {
        state=false;
        }

        return state;
    }
     void resetCheckBoxes()
    {
        jCheckBox1.setSelected(false);
        jCheckBox2.setSelected(false);
        jCheckBox3.setSelected(false);
        jCheckBox4.setSelected(false);
        jCheckBox5.setSelected(false);
        jCheckBox6.setSelected(false);
        jCheckBox7.setSelected(false);

    }
     void reset()
    {
        resetFields();
        resetCountry();
        resetVendorID();
        disableFields();
        resetCheckBoxes();
    }
     void submitData()
    {
        //Connect.createMSSQLConnection();
        Connect.changeDB(OpenMSApp.Database_A);
        statement=Connect.createStatement(Connect.procInit+"  prnUpdVendor"+Connect.procInitStart+"?,?,?,?,?,?,?,?"+Connect.procInitEnd);
            try{
            statement.setString(1,vendorIDComboBox.getSelectedItem().toString());
            statement.setString(2,jAddressTextArea.getText());
            statement.setString(3,jCityTextField.getText());
            statement.setString(4,jStateTextField.getText());
            statement.setString(5,jCountryComboBox.getSelectedItem().toString());
            statement.setString(6,jZipTextField.getText());
            statement.setString(7,jPhoneTextField.getText());
            statement.setString(8,jRegNoTextField.getText());
            }
            catch(Exception e)
            {
            System.out.println("EditVendor.submitData() gave error ! "+e);
            }
        Connect.alert="Y";
        Connect.executeUpdateStatement(statement);
        Connect.closeConnection();
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jAddressLabel;
    private javax.swing.JTextArea jAddressTextArea;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JCheckBox jCheckBox6;
    private javax.swing.JCheckBox jCheckBox7;
    private javax.swing.JTextField jCityTextField;
    private javax.swing.JComboBox jCountryComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField jNameTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jPhoneTextField;
    private javax.swing.JTextField jRegNoTextField;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jStateTextField;
    private javax.swing.JButton jUpdateButton;
    private javax.swing.JTextField jZipTextField;
    private javax.swing.JComboBox vendorIDComboBox;
    // End of variables declaration//GEN-END:variables

}
